package com.example.Annocation.conditional;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;


/**
 * @Description TODO
 * @Date 2024/5/14 22:43
 * @Created by houjunfeng
 */
public class WindowsConditional implements Condition {
    @Override
    public boolean matches(ConditionContext var1, AnnotatedTypeMetadata var2){
        //获取IOC使用的当前的bean工厂
        ConfigurableListableBeanFactory configurableListableBeanFactory = var1.getBeanFactory();
        //获取类加载器
        ClassLoader classLoader = var1.getClassLoader();
        //获取当前虚拟机环境变量
        Environment environment = var1.getEnvironment();
        String property = environment.getProperty("os.name");
        //获取bean定义的注册类
        BeanDefinitionRegistry beanDefinitionRegistry = var1.getRegistry();
        Boolean flag = beanDefinitionRegistry.containsBeanDefinition("Student001");
        if(flag&&property.contains("Windows")){
            return true;
        }
        return  false;
    }

}
